package com.study.authority;

import java.util.Objects;

public class TestEquals {
    public static void main(String[] args) {
        String str1 = "100";
        String str2 = "100";
        Big b1 = new Big();
        Big b2 = new Big();
        //Object类中定义了equals方法，所有类继承于Object类
        //public boolean equals(Object obj) {
        //        return (this == obj);
        //    }
        //String类中重写了equals方法
//        public boolean equals(Object anObject) {
//            if (this == anObject) {
//                return true;
//            }
//            if (anObject instanceof String) {
//                String aString = (String)anObject;
//                if (!COMPACT_STRINGS || this.coder == aString.coder) {
//                    return StringLatin1.equals(value, aString.value);
//                }
//            }
//            return false;
//        }
//        public static boolean equals(byte[] value, byte[] other) {
//            if (value.length == other.length) {
//                for (int i = 0; i < value.length; i++) {
//                    if (value[i] != other[i]) {
//                        return false;
//                    }
//                }
//                return true;
//            }
//            return false;
//        }
        System.out.println(str1.equals(str2));
        System.out.println(b1.equals(b2));
    }
}
class Big{
    String name;
    int age;
    double weight;
    boolean isMale;

    @Override
    public boolean equals(Object o) {
        if (this == o) return true;
        if (o == null || getClass() != o.getClass()) return false;
        Big big = (Big) o;
        return age == big.age &&
                Double.compare(big.weight, weight) == 0 &&
                isMale == big.isMale &&
                Objects.equals(name, big.name);
    }
}